<?php
require_once '../library/fungsi.lib.php';

$kode = !isset($_GET["kode"]) ? 0 : anti_injection($_GET["kode"]);

$sql_trx = "SELECT * FROM tr_x WHERE trx_kodeunik='$kode' ";
$hasil_trx = mysql_query($sql_trx);
$baris_trx = mysql_num_rows($hasil_trx);

if ($baris_trx < 1) {
    
} else {

    if ($baris_trx == 1) {
        $trx_id = mysql_result($hasil_trx, "0", "trx_id");
        $trx_kodeunik = mysql_result($hasil_trx, "0", "trx_kodeunik");
        $trx_angkaunik = mysql_result($hasil_trx, "0", "trx_angkaunik");
        $trx_waktu = get_format_waktu_full(mysql_result($hasil_trx, "0", "trx_waktu"));
        $trx_total = mysql_result($hasil_trx, "0", "trx_total");
        $trx_status = mysql_result($hasil_trx, "0", "trx_status");
        $trx_ongkir = mysql_result($hasil_trx, "0", "trx_ongkir");
        $trx_nama = mysql_result($hasil_trx, "0", "trx_nama");
        $trx_alamat = mysql_result($hasil_trx, "0", "trx_alamat");
        $trx_notelp = mysql_result($hasil_trx, "0", "trx_notelp");
        //$trx_email = mysql_result($hasil_trx, "0", "trx_email");
        $trx_ongkir_id = mysql_result($hasil_trx, "0", "trx_ongkir_id");
        $trx_kota = get_ongkir_kota_from_id($trx_ongkir_id);
        $trx_noresi = mysql_result($hasil_trx, "0", "trx_noresi");
    }
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Nota Pembelian</title>
        </head>
        <body>
            <div div style="border:0;padding:0;margin:5px;font-family:Tahoma,Geneva,sans-serif;font-size:11px;width:650px;line-height:18px">
                <table width="650px" cellspacing="0" cellpadding="0" border="0">
                    <tbody>
                        <tr>
                            <td>
                                <div style="background-color:#e1ecf9;padding:5px 10px;border:1px solid #bfd7ff;width:625px">
                                    <div style="float:left;padding:5px"><img></div>
                                    <div style="float:right;font-size:25px;padding-top:10px;padding-right:5px">
                                        Online Invoice</div>
                                    <div style="clear:both"></div>
                                </div>
                                <table width="645px;" cellspacing="0" cellpadding="5" border="0" style="text-align:left;font-size:11px;line-height:15px;margin-top:5px">
                                    <tbody><tr valign="top">
                                            <td width="50%">
                                                <table width="100%" cellpadding="1" style="border:1px solid #cccccc">
                                                    <tbody><tr>
                                                            <th style="font-size:12px;padding-left:15px;background:url() left no-repeat" colspan="3">Transaction Details</th>
                                                        </tr>
                                                        <tr>
                                                            <td width="110px">&nbsp;Transaction Code</td>
                                                            <td width="8px">:</td>
                                                            <td><b><?php echo $trx_kodeunik; ?> </b></td>
                                                        </tr>
                                                        <tr>
                                                            <td width="110px">&nbsp;Time of Transaction</td>
                                                            <td width="5px">:</td>
                                                            <td><?php echo $trx_waktu; ?></td>
                                                        </tr>

                                                        <tr>
                                                            <td width="110px">&nbsp;Shipping Method</td>
                                                            <td width="5px">:</td>
                                                            <td>JNE REG</td>
                                                        </tr>
                                                        <tr>
                                                            <td width="110px">&nbsp;Shipping Cost</td>
                                                            <td width="5px">:</td>
                                                            <td>Rp. <?php echo format_rupiah($trx_ongkir); ?> x 1 kg</td>
                                                        </tr>
                                                        <tr>
                                                            <td width="110px">&nbsp;Total Payment</td>
                                                            <td width="5px">:</td>
                                                            <td><span style="color:#163aee;font-weight:bold">Rp. <?php echo format_rupiah($trx_total); ?></span></td>
                                                        </tr>
                                                        <tr>
                                                            <td width="110px">&nbsp;Kode Unik</td>
                                                            <td width="5px">:</td>
                                                            <td><span style="color:#163aee;font-weight:bold"><?php echo $trx_angkaunik; ?></span></td>
                                                        </tr>
                                                        <tr>
                                                            <td width="110px">&nbsp;Payment Status</td>
                                                            <td width="5px">:</td>
                                                            <td style="font-weight:bold">
                                                                <?php echo get_status_transaksi($trx_status); ?> </td>
                                                        </tr>
                                                    </tbody></table>
                                            </td>

                                            <td width="50%">
                                                <table width="100%" cellpadding="1" style="border:1px solid #cccccc">
                                                    <tbody><tr>
                                                            <th style="font-size:12px;padding-left:15px;background:url() left no-repeat" colspan="3">
                                                                Shipping Information
                                                            </th>
                                                        </tr>
                                                        <tr>
                                                            <td width="100px">&nbsp;Recipient Name</td>
                                                            <td width="8px">:</td>
                                                            <td><b><?php echo $trx_nama; ?></b></td>
                                                        </tr>
                                                        <tr>
                                                            <td>&nbsp;Phone</td>
                                                            <td>:</td>
                                                            <td><?php echo $trx_notelp; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <td>&nbsp;Address</td>
                                                            <td>:</td>
                                                            <td><?php echo $trx_alamat; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <td>&nbsp;City</td>
                                                            <td>:</td>
                                                            <td><?php echo $trx_kota; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <td>&nbsp;No Resi</td>
                                                            <td>:</td>
                                                            <td><?php echo ($trx_noresi == NULL) ? '-' : $trx_noresi; ?></td>
                                                        </tr>
                                                    </tbody></table>
                                            </td>
                                        </tr>
                                    </tbody></table><div style="width:650px">
                                    <div style="font-size:12px;font-weight:bold;padding-left:10px;margin-bottom:5px;margin-left:10px;background:url() left no-repeat">
                                        Order Details
                                    </div>
                                    <div style="border:1px solid #ccc;margin:0 5px">
                                        <div style="background-color:#e1ecf9;color:#35689f;font-weight:bold;margin:2px">
                                            <div style="float:left;padding:3px 5px;text-align:center;width:70px">No</div>
                                            <div style="float:left;padding:3px 5px;text-align:left;width:240px">Item Name</div>
                                            <div style="float:left;padding:3px 5px;text-align:right;width:90px">Size</div>
                                            <div style="float:left;padding:3px 5px;text-align:center;width:50px">Qty</div>
                                            <div style="float:left;padding:3px 5px;text-align:center;width:50px">Weight (gram)</div>
                                            <div style="float:left;padding:3px 5px;text-align:right;width:70px">Total</div>
                                            <div style="clear:both"></div>
                                        </div>
                                        <div style="clear:both"></div>

                                        <?php
                                        $sql = "SELECT * FROM tr_d WHERE trd_trx_id='$trx_id' ORDER BY trd_id ";
                                        $hasil = mysql_query($sql);

                                        $no = 1;
                                        $trx_berat = 0;
                                        while ($row = mysql_fetch_array($hasil)) {
                                            ?>
                                            <div>
                                                <div style="float:left;padding:3px 5px;text-align:center;width:70px"><?php echo $no; ?></div>
                                                <div style="float:left;padding:3px 5px;text-align:left;width:240px"><?php echo get_produk_name_from_id($row["trd_produk_id"]); ?></div>
                                                <div style="float:left;padding:3px 5px;text-align:right;width:90px"><?php echo strtoupper($row["trd_ukuran"]); ?></div>
                                                <div style="float:left;padding:3px 5px;text-align:center;width:50px"><?php echo $row["trd_jumlah"]; ?></div>
                                                <div style="float:left;padding:3px 5px;text-align:center;width:50px"><?php echo $row["trd_berat"]; ?></div>
                                                <div style="float:left;padding:3px 5px;text-align:right;width:70px"><?php echo format_rupiah($row["trd_harga"]); ?></div>
                                                <div style="clear:both"></div>
                                            </div>
                                            <?php
                                            $trx_berat += $row["trd_berat"];
                                            $no++;
                                        }
                                        ?>

                                        <div style="border:1px solid #ccc;margin:0 5px"></div> 
                                        <div style="float:left;padding:3px 5px;text-align:center;width:70px">&nbsp;</div>
                                        <div style="float:left;padding:3px 5px;text-align:left;width:260px">Biaya Pengiriman JNE REG (1 kg) + ADM </div>
                                        <div style="float:left;padding:3px 5px;text-align:right;width:70px">-</div>
                                        <div style="float:left;padding:3px 5px;text-align:center;width:50px">-</div>
                                        <div style="float:left;padding:3px 5px;text-align:center;width:50px"><?php echo $trx_berat; ?></div>
                                        <div style="float:left;padding:3px 5px;text-align:right;width:70px"><?php echo $trx_ongkir; ?></div>
                                        <div style="clear:both"></div>

                                        <div style="float:left;padding:3px 5px;text-align:center;width:70px">&nbsp;</div>
                                        <div style="float:left;padding:3px 5px;text-align:left;width:240px">Kode Unik</div>
                                        <div style="float:left;padding:3px 5px;text-align:right;width:90px">-</div>
                                        <div style="float:left;padding:3px 5px;text-align:center;width:50px">-</div>
                                        <div style="float:left;padding:3px 5px;text-align:center;width:50px">-</div>
                                        <div style="float:left;padding:3px 5px;text-align:right;width:70px"><?php echo $trx_angkaunik; ?></div>
                                        <div style="clear:both"></div>

                                        <div style="border:1px solid #ccc;margin:0 5px"></div>
                                        <div style="float:left;padding:3px 5px;text-align:center;width:70px">&nbsp;</div>
                                        <div style="float:left;padding:3px 5px;text-align:left;width:240px">&nbsp;</div>
                                        <div style="font-weight:bold;color:#35689f;float:left;padding:3px 5px;text-align:right;width:90px">Grand Total</div>
                                        <div style="font-weight:bold;color:#35689f;float:left;padding:3px 5px;text-align:center;width:50px">&nbsp;</div>
                                        <div style="font-weight:bold;color:#35689f;float:left;padding:3px 5px;text-align:center;width:50px"><?php echo ceil($trx_berat / 1000); ?>*</div>
                                        <div style="font-weight:bold;color:#35689f;float:left;padding:3px 5px;text-align:right;width:70px"><?php echo format_rupiah($trx_total); ?></div>
                                        <div style="clear:both"></div>
                                    </div>

                                    <div style="padding-left:5px;font-style:italic">
                                        * Berat pengiriman dibulatkan ke atas
                                    </div> <div style="padding:15px 5px 5px 5px">
                                        Kepada Yth. <b>Bapak/Ibu <?php echo $trx_nama; ?></b>, <br>Terima kasih atas kepercayaan Anda berbelanja di e-rider.
                                    </div>
                                </div>
                                <?php if ($trx_status == '1') { ?>
                                    <div style="padding:0 5px 0 5px">
                                        Sebagai informasi, Nota Pembelian ini bukan sebagai bukti pembelian dan <b>hanya sah</b> apabila Anda telah
                                        melakukan pembayaran ke nomor rekening resmi kami yang tertera di bawah.

                                        <div style="margin:10px 15px 10px 0px;padding:0px;border-top:1px solid #ddd;border-left:1px solid #ddd;width:630px">
                                            <div style="width:304px;border-right:1px solid #ddd;border-bottom:1px solid #ddd;float:left;padding:5px">
                                                <img alt="BCA" style="float:left">
                                                <b>467-119-3908</b> a/n Jualan Rider<br>
                                                Cab. Mal Taman Anggrek </div>
                                            <div style="width:304px;border-right:1px solid #ddd;border-bottom:1px solid #ddd;float:left;padding:5px">
                                                <img alt="Mandiri" style="float:left">
                                                <b>1170004531455</b> a/n Jualan Rider<br>
                                                Cab. Taman Anggrek, Jakarta Barat </div>
                                            <div style="clear:both"></div>
                                        </div>
                                    </div>

                                    <div style="text-align:center;margin-bottom:10px;margin-top:8px">
                                        <div style="border-top:1px solid #e0e0e0;border-bottom:1px solid #e0e0e0;padding:5px;text-align:center;width:450px;margin:auto">
                                            <img align="left">
                                            <img align="right">
                                            Diharapkan untuk melakukan pembayaran transfer menggunakan <label style="color:blue;text-decoration:underline">kode unik</label> agar pesanan anda bisa segera diproses secara otomatis oleh sistem kami
                                        </div>
                                    </div>
                                    <div style="clear:both"></div>
                                <?php } ?>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </body>
    </html>
    <?php
}
?>